﻿using System;

using Framework.Validation;
using Framework.Validation.Implementation;

namespace Framework.Domain.Validation
{
    /// <summary>
    /// Implements base logic of domain object validation.
    /// </summary>
    public abstract class DomainObjectValidator : IValidator
    {
        private readonly IValidationResultFactory resultFactory;

        /// <summary>
        /// Initializes a new instance of the <see cref="DomainObjectValidator"/> class.
        /// </summary>
        /// <param name="resultFactory">The <see cref="IValidationResultFactory" /> instance.</param>
        protected DomainObjectValidator(IValidationResultFactory resultFactory)
        {
            if (resultFactory == null)
            {
                throw new ArgumentNullException("resultFactory");
            }

            this.resultFactory = resultFactory;
        }

        /// <summary>
        /// Gets the <see cref="IValidationResultFactory" />.
        /// </summary>
        protected IValidationResultFactory ResultFactory
        {
            get
            {
                return resultFactory;
            }
        }

        /// <summary>
        /// Creates the <see cref="IValidationResults" />.
        /// </summary>
        protected virtual ValidationResults CreateResults()
        {
            return new ValidationResults();
        }

        /// <inheritdoc />
        public abstract IValidationResults Validate(object validatable);
    }
}
